#include "hashmap.h"
/*int main()
{
	hashmap *map = hashmap_create(10);
	hashmap_put(map,"name","xddai");
	char *name=(char *)hashmap_get(map,"name");
	printf("%s\n",name);
	hashmap_destroy(map);
}*/
int hashmap_put(hashmap *map,char *key,void *value)
{
	ENTRY en;
	en.key = key;
	en.data = value;
	ENTRY *demp;
	map->size += 1;
	return hsearch_r(en,ENTER,&demp,map->htab);
}
void * hashmap_get(hashmap *map,char *key)
{
	ENTRY en;
	en.key=key;
	en.data=NULL;
	ENTRY *demp;
	hsearch_r(en,FIND,&demp,map->htab);
	return demp->data;
}
int hashmap_destroy(hashmap *map)
{
	hdestroy_r(map->htab);
	free(map);
}

hashmap* hashmap_create(int maxSize)
{
	hashmap* map = (hashmap *)malloc(sizeof (hashmap));
	map->htab = (struct hsearch_data *)calloc(sizeof(struct hsearch_data),1);
	map->maxSize = maxSize;
	map->size = 0;
	hcreate_r(maxSize,map->htab);
	return map;
}

